package pku;

/**
 * Created by yangxiao on 2017/11/14.
 *
 */
public class DefaultMessage implements ByteMessage {

    private KeyValue headers = new DefaultKeyValue();
    private byte[] body;
    private KeyValue properties;

    public void setHeaders(KeyValue headers) {
        this.headers = headers;
    }

    public DefaultMessage(byte[] body) {
        this.body = body;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public KeyValue headers() {
        return headers;
    }

    public KeyValue properties() {
        return properties;
    }

    public DefaultMessage putHeaders(String key, int value) {
        headers.put(key, value);
        return this;
    }

    public DefaultMessage putHeaders(String key, long value) {
        headers.put(key, value);
        return this;
    }

    public DefaultMessage putHeaders(String key, double value) {
        headers.put(key, value);
        return this;
    }

    public DefaultMessage putHeaders(String key, String value) {
        headers.put(key, value);
        return this;
    }

    public ByteMessage putProperties(String key, int value) {
        if (properties == null) properties = new DefaultKeyValue();
        properties.put(key, "i"+value);
        return this;
    }

    public ByteMessage putProperties(String key, long value) {
        if (properties == null) properties = new DefaultKeyValue();
        properties.put(key, "l"+value);
        return this;
    }

    public ByteMessage putProperties(String key, double value) {
        if (properties == null) properties = new DefaultKeyValue();
        properties.put(key, "d"+value);
        return this;
    }

    public ByteMessage putProperties(String key, String value) {
        if (properties == null) properties = new DefaultKeyValue();
        properties.put(key, "s"+value);
        return this;
    }

    public void setHeaders(DefaultKeyValue headers) {
        this.headers = headers;
    }

    public void setProperties(DefaultKeyValue properties) {
        this.properties = properties;
    }
}
